package cn.com.smart.conf;

import cn.com.smart.common.AiConstants;
import cn.com.smart.framework.config.properties.DruidProperties;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class AiDataSourceConfig {
	
	 	@Bean(name=AiConstants.AI_DS_NAME)
	    @ConfigurationProperties("spring.datasource.druid.ai")
	    @ConditionalOnProperty(prefix = "spring.datasource.druid.ai", name = "enabled", havingValue = "true")
	    public DataSource biDataSource(DruidProperties druidProperties)
	    {
	        DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
	        return druidProperties.dataSource(dataSource);
	    }

}
